package com.zx.wangyixinwen.fragment;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.DrawerLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.zx.wangyixinwen.R;
import com.zx.wangyixinwen.adapter.NewsAdapter;

import java.util.ArrayList;

/**
 * Created by dllo on 16/1/4.
 */
public class NewsFragment extends Fragment implements View.OnClickListener {
    private ViewPager viewPager;
    private TabLayout tabLayout;
    private ArrayList<Fragment> datas;
    private NewsAdapter adapter;
    private DrawerLayout drawerLayout;



    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//        DayNightMode.onActivityCreateSetTheme(this);
        View view = inflater.inflate(R.layout.fragment_news, null);
//        view.findViewById(R.id.btn_day).setOnClickListener(this);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
//        view.findViewById(R.id.btn_drawe).setOnClickListener(this);
//        drawerLayout = (DrawerLayout) view.findViewById(R.id.drawer_layout);

        viewPager = (ViewPager) view.findViewById(R.id.viewPager_news);
        tabLayout = (TabLayout) view.findViewById(R.id.tabLayout_mews);
        datas = new ArrayList<>();
        datas.add(new HeadlinesFragment());
        datas.add(new JokesFragment());
        datas.add(new WomanFragment());
        adapter = new NewsAdapter(getActivity().getSupportFragmentManager(), getActivity(), datas);
        viewPager.setAdapter(adapter);
        tabLayout.setTabTextColors(Color.BLACK, Color.BLUE);
        tabLayout.setupWithViewPager(viewPager);

    }


    @Override
    public void onClick(View v) {
//        switch (v.getId()){
////            int theme = DayNightMode.getDayNightMode(getActivity());
////            int theme = DayNightMode.getDayNightMode(getActivity());
//            case R.id.btn_day:
//                if (theme == DayNightMode.THEME_SUN) {
//                    DayNightMode.setDayNightMode(getActivity(),DayNightMode.THEME_NIGHT);
//                } else {
//                    DayNightMode.setDayNightMode(getActivity(),DayNightMode.THEME_SUN);
//                }
//                // 注意改过主题后一定要，把activity finish在重开一遍，因为更改主题只能在oncreat中进行
//                getActivity().finish();
//                getActivity().startActivity(new Intent(getActivity(),getActivity().getClass()));
//                break;
//        }
    }
}
